---
title: Exceptions & Retries
---

If after a tool call we need to "retry" the model with a different set of instructions or stop the agent, we can raise one of the following exceptions:

- `RetryAgentRun`: Use this exception when you want to retry the agent run with a different set of instructions.
- `StopAgentRun`: Use this exception when you want to stop the agent run.
- `AgentRunException`: A generic exception that can be used to retry the tool call.


This example shows how to use the `RetryAgentRun` exception to retry the agent with additional instructions.

```python retry_in_tool_call.py
from agno.agent import Agent
from agno.exceptions import RetryAgentRun
from agno.models.openai import OpenAIChat
from agno.utils.log import logger
from agno.run import RunContext


def add_item(run_context: RunContext, item: str) -> str:
    """Add an item to the shopping list."""
    if not run_context.session_state:
        run_context.session_state = {}

    run_context.session_state["shopping_list"].append(item)
    len_shopping_list = len(run_context.session_state["shopping_list"])
    if len_shopping_list < 3:
        raise RetryAgentRun(
            f"Shopping list is: {run_context.session_state['shopping_list']}. Minimum 3 items in the shopping list. "
            + f"Add {3 - len_shopping_list} more items.",
        )

    logger.info(f"The shopping list is now: {run_context.session_state.get('shopping_list')}")
    return f"The shopping list is now: {run_context.session_state.get('shopping_list')}"


agent = Agent(
    model=OpenAIChat(id="gpt-5-mini"),
    # Initialize the session state with empty shopping list
    session_state={"shopping_list": []},
    tools=[add_item],
    markdown=True,
)
agent.print_response("Add milk", stream=True)
print(f"Final session state: {agent.get_session_state()}")
```

<Tip>
Make sure to set `AGNO_DEBUG=True` to see the debug logs.
</Tip>
